<?php

/**
 * EmsForm form.
 *
 * @package    ems1
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class EmsFormForm extends BaseEmsFormForm
{
    public function configure()
    {
        unset ($this['created_at'], $this['updated_at'], $this['element_id']);

        $fields = $this->getObject()->getFields();

        $this->widgetSchema->setLabels(array(
            'uses_external_feed' => 'Con conexión externa',
            'webservice_url'     => 'Url del servicio web',
        ));

        if(!$fields->count()){
            $fields = array();
            $field = new EmsFormField();
            $this->getObject()->getFields()->add($field);
            $fields= array($field);
        }
        //A contaneir for the fields forms
        $fields_forms = new sfForm();
        foreach ($fields as $i=>$field){
            $field_form = new EmsFormFieldForm($field);
            //Embedding each form in the container
            $fields_forms->embedForm($i, $field_form);
        }

        //Embedding the container in the main form
        $this->embedForm('Fields', $fields_forms);
    }

    public function addField($num)
    {
        $field = new EmsFormField();
        $this->getObject()->getFields()->add($field, $num);
        $field_form = new EmsFormFieldForm($field, array('portal_id' => $this->getOption('portal_id')));
        $this->embeddedForms['Fields']->embedForm($num, $field_form);
        $this->embedForm('Fields', $this->embeddedForms['Fields']);
    }
}
